package com.akkainaction.tool.eventbus.bus;

import akka.actor.ActorRef;
import akka.event.japi.LookupEventBus;
import com.akkainaction.tool.eventbus.event.Event;

public class EventBusDemo extends LookupEventBus<Event, ActorRef, String> {

    /**
     * 期望的classfier数目，一般设置为2的N次方
     * @return
     */
    @Override
    public int mapSize() {
        return 8;
    }

    @Override
    public int compareSubscribers(ActorRef ref1, ActorRef ref2) {
        return ref1.compareTo(ref2);
    }

    @Override
    public String classify(Event event) {
        return event.getType();
    }

    @Override
    public void publish(Event event, ActorRef ref) {
        ref.tell(event.getMessage(),ActorRef.noSender());
    }
}
